package com.unittec.drainage.provider.root;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author: trace
 * @date: 2019-06-12.
 * @Description:
 * @Email: tracenet@126.com
 */
public abstract class ServiceRoot<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IService<T> {

    @Autowired
    private M m;

    public M getMapper() {
        return m;
    }

    @Override
    public List<T> listByIds(Collection<? extends Serializable> idList) {
        Collection<T> ts = super.listByIds(idList);
        return toList(ts);
    }

    private List<T> toList(Collection<T> ts) {
        if (ts instanceof List) {
            return (List)ts;
        } else {
            return new ArrayList(ts);
        }
    }
}
